#!/usr/bin/env python

import wx
import sys
import component

class Info(component.ListCtrl):
    '''Info class
    
    @author Julot <andy.julot@gmail.com>
    @since Friday, January 27, 2012. 06:21 PM'''
    
    def __init__(self, parent):
        style = wx.LC_REPORT | wx.LC_SINGLE_SEL
        component.ListCtrl.__init__(self, parent, style=style)
        self.InsertColumn(0, "Key")
        self.InsertColumn(1, "Value")
        self.SetColumnWidth(1, wx.LIST_AUTOSIZE)
    
    _values  = []
    
    def getValues(self):
        return self._values
    
    def setValues(self, values):
        self._values = values
        self.DeleteAllItems()
        for dic in values:
            for key in dic:
                pos = self.InsertStringItem(sys.maxint, label=key)
                self.SetStringItem(pos, 1, dic[key])
    
    values = property(getValues, setValues)
    
    _value = None
    
    def getValue(self):
        return self._value
    
    def setValue(self, value):
        self._value = value
        values = []
        if value.episodecount == '?':
            s = '%s, unknown number of episodes' % value.type
        else:
            s = '%s, %s episodes' % (value.type, value.episodecount)
        values.append({'Type': s})
        values.append({'Year': '%s till %s' % (value.startdate, value.enddate)})
        for title in value.titles:
            s = '%s (%s)' % (title.value, title.humanLanguage)
            values.append({title.humanType: s})
        self.values = values
    
    value = property(getValue, setValue)
    
    def clear(self):
        self.DeleteAllItems()